c_ij = [
    [0,5,21,13,6,15,12,20],
    [5,0,16,18,7,12,19,17],
    [21,16,0,33,16,7,17,11],
    [13,18,33,0,17,26,16,29],
    [6,7,16,17,0,9,12,14],
    [15,12,7,26,9,0,10,5],
    [18,19,17,16,12,10,0,13],
    [20,17,11,29,14,5,13,0]
]
N = len(c_ij)
inf = 100000
def N_N(visited,waiting,current_len,c_ij):
    visited_greed = list(visited)
    len = current_len
    waiting_greed = list(waiting)
    #贪心求循环剩余结点回到起点的距离和路径
    while waiting_greed:
        tem = inf
        next = None
        for j in waiting_greed:
            if c_ij[visited_greed[-1]][j] < tem:
                tem = c_ij[visited_greed[-1]][j]
                next = j
        visited_greed.append(next)
        waiting_greed.remove(next)
        len += tem
    len += c_ij[visited_greed[-1]][0]
    visited_greed.append(0)
    return len,visited_greed
print(N_N([0],[1,2,3,4,5,6,7],0,c_ij))